﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Text;
using EIS.ClientUtility;
using EIS.Obj;
using EIS.ServerAdapter;

namespace Ext.Connector.EIS
{
    public class SFObject:SAPConnector
    {
        public SFObject(string functionID)
        {
            this.FunctionID = functionID;
        }

        private void Connect()
        {

        }

        public override void Execute(object args)
        {
            string url = GlobalVariable.Instance.ServerRootURL;

            url = url + @"functionConfig/" + FunctionID + @"/" + GlobalVariable.Instance.CurrentToken + ".xml";

            DataSet dsConfig = RestAdapter.HttpGet(url);

            if ((dsConfig == null) || (dsConfig.Tables.Count == 0)) return;
            var dr = dsConfig.Tables[0].Rows[0];




            var dataRow = (DataRowView)args;

            string SFObjId = dataRow["SFObjId"].ToString();

            if (SFObjId == String.Empty)
            {

                ShowErrorMessageBox.Show("Error in Getting Salesforce Object");
            }
            else
            {
                string urlDest = "https://na15.salesforce.com";// = dr["BaseURL"].ToString();
                urlDest = urlDest + "/" + SFObjId;
                Process.Start(urlDest);
            }
        }
    }
}
